import { useAuthStore } from "@/store/modules/auth";
import { getStorage } from ".";

export const upload = () => {
  return new Promise((resolve, reject) => {
    uni.chooseImage({
      success: (chooseImageRes) => {
        const tempFilePaths = chooseImageRes.tempFilePaths;
        uni.uploadFile({
          url: `${import.meta.env.VITE_APP_BASE_URL}/common/upload`,
          filePath: tempFilePaths[0],
          header: {
            Authorization: getStorage("accessToken"),
          },
          name: "file",
          formData: {
            // 'user': 'test'
          },
          success: (uploadFileRes) => {
            let data = JSON.parse(uploadFileRes.data);
            resolve(data);
            // console.log(typeof(uploadFileRes.data), JSON.parse(
            // 	uploadFileRes.data).msg);
          },
        });
      },
    });
  });
};
